package diploma.kisel.modelas.service;

import java.util.List;

import diploma.kisel.modelas.domain.Device;
import diploma.kisel.modelas.domain.DeviceType;
import diploma.kisel.modelas.repository.DeviceRepositoryImpl;
import diploma.kisel.modelas.repository.api.DeviceRepository;
import diploma.kisel.modelas.service.api.DeviceService;

public class DeviceServiceImpl implements DeviceService{
	
	private DeviceRepository deviceRepository = new DeviceRepositoryImpl();

	@Override
	public List<Device> findAll() {
		return deviceRepository.findAll();
	}

	@Override
	public List<Device> findByPrice(int minPrice, int maxPrice) {
		return deviceRepository.findByPrice(minPrice, maxPrice);
	}

	@Override
	public Device findById(int id) {
		if (id>=0)
			return deviceRepository.findById(id);
		else
			return null;
	}

	@Override
	public Device save(Device device) {
		if (device.getId()!=null)
			return deviceRepository.update(device);
		else
			return deviceRepository.save(device);
	}

	@Override
	public void remove(Device device) {
		if (device.getId()!=null)
			deviceRepository.remove(device);		
	}

	@Override
	public void remove(int id) {
		Device device = deviceRepository.findById(id);
		deviceRepository.remove(device);		
	}

	@Override
	public List<Device> findByPriceAndType(int minPrice, int maxPrice,
			DeviceType type) {
		return deviceRepository.findByPriceAndType(minPrice, maxPrice, type);
	}

}
